package com.mall4j.cloud.product.controller.admin;

import com.mall4j.cloud.common.response.ServerResponseEntity;
import com.mall4j.cloud.product.dto.RequestResourceDTO;
import com.mall4j.cloud.product.service.ResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;


@RestController("mpResourceController")
@RequestMapping("/mp/resource")
@Api(tags = "资源同步接口")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    /*
     * 性能：万级数据保证10S内更新
     * */
    @ApiOperation(value = "开放接口-接收ERP资源推送")
    @PostMapping("receive")
    public ServerResponseEntity receive(@Valid @RequestBody List<RequestResourceDTO> resourceDTOList) {
        // TODO: 2023/2/24 这里是测试代码------------------
        RequestResourceDTO test = new RequestResourceDTO();
        for (int i = 0; i < 10000; i++) {
            resourceDTOList.add(test.getMock());
        }
        // TODO: 2023/2/24 这里是测试代码------------------

        resourceService.handleReceive(resourceDTOList);
        return ServerResponseEntity.success();
    }

}
